package com.qidianit.mes.pro.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.Workstation;
import com.qidianit.mes.pro.service.WorkstationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Author: YKYB
 * @Date: 2025/10/1 15:10
 * @Description:
 */
@RestController
@RequestMapping("/workstation")
public class WorkstationController {
    @Autowired
    private WorkstationService workstationService;

    /**
     * 多条件分页查询工作站
     */
    @GetMapping("/page")
    public Result<PageInfo<Workstation>> page(
            Workstation workstation,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return Result.success(workstationService.selectList(workstation, pageNum, pageSize));
    }

    /**
     * 根据编码查询工作站
     */
    @GetMapping("/code/{code}")
    public Result<Workstation> getByCode(@PathVariable String code) {
        return workstationService.getByCode(code);
    }


    /**
     * 接口3：新增工作站
     */
    @PostMapping
    public Result<Workstation> add(@RequestBody Workstation workstation) {
        return workstationService.add(workstation);
    }

    /**
     * 接口4：更新工作站
     */
    @PutMapping
    public Result<Workstation> update(@RequestBody Workstation workstation) {
        return workstationService.update(workstation);
    }

    /**
     * 接口5：删除工作站
     */
    @DeleteMapping("/{id}")
    public Result<Workstation> deleteById(@PathVariable Long id) {
        return workstationService.deleteById(id);
    }

    /**
     * 接口6：批量删除工作站
     */
    @DeleteMapping("/batch")
    public Result<Void> batchDelete(@RequestBody List<Long> ids) {
        return workstationService.batchDelete(ids);
    }

    /**
     * 接口7：修改工作站状态
     */
    @PutMapping("/{id}/status")
    public Result<Workstation> changeStatus(@PathVariable Long id,
                                            @RequestParam Integer status) {
        return workstationService.changeStatus(id, status);
    }

    /**
     * 接口8：根据车间ID查询工作站列表
     */
    @GetMapping("/workshop/{workshopId}")
    public Result<List<Workstation>> getByWorkshopId(@PathVariable Long workshopId) {
        return workstationService.getByWorkshopId(workshopId);
    }
}

